<template>
  <div class="main">
    <div class="main-warpper">
      <div class="main-left">
        <p class="header">
          <img src="../../assets/images/user.png"/>
          <span>个人中心</span>
        </p>
        <ul class="nav-list">
          <li :class="{'active': activeIndex == index}" v-for="(nav, index) in navigation" :key="index" @click="redirectTo(index)">
            {{nav.title}}
          </li>
        </ul>
      </div>
      <div class="main-right">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      activeIndex: 0,
      navigation: [
        {
          title: '我的订单',
          path: '/user/order'
        },
        {
          title: '我的优惠券',
          path: '/user/coupons'
        },
        {
          title: '账号管理',
          path: '/user/account'
        },
        {
          title: '消息',
          path: '/user/message',
          messageNum: 0
        },
        {
          title: '收藏的商品',
          path: '/user/favoriteGoods'
        },
        {
          title: '关注的店铺',
          path: '/user/favoriteStores'
        },
        {
          title: '地址管理',
          path: '/user/address'
        },
        {
          title: '领样记录',
          path: '/user/record'
        },
        // {
        //   title: '开票中心',
        //   path: '/user/bill'
        // },
        {
          title: '售后管理',
          path: '/user/afterSales'
        }
      ]
    }
  },
  mounted () {
    this.navigation.forEach((item, index) => {
      if (item.path === this.$router.history.current.fullPath) {
        this.activeIndex = index
      }
    })
  },
  methods: {
    redirectTo (index) {
      this.activeIndex = index
      this.$router.push(this.navigation[index].path)
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/assets/scss/basic.scss';
  .main{
    width: 100%;
    .main-warpper{
      width: 1200px;
      margin: 0 auto;
      padding: 45px 0 105px 0;
      display: flex;
      align-items: flex-start;
      .main-left{
        width: 122px;
        margin-right: 30px;
        border: 1px solid $border_color;
        box-shadow: 0 1px 6px rgba(128, 128, 128, 0.3);
        font-size: $fz_14;
        .header{
          width: 120px;
          color: #ffffff;
          height: 33px;
          display: flex;
          align-items: center;
          background: url(../../assets/images/icon-userbg.png) no-repeat;
          background-size: cover;
          img{
            width: 18px;
            height: 18px;
            margin: 0 3px 0 20px;
          }
          span{text-align: center;}
        }
        .nav-list{
          padding: 20px 0 30px 0;
          width: 120px;
          background: #ffffff;
          li{
            height: 32px;
            line-height: 32px;
            padding-left: 27px;
            color: $f_main;
            cursor: pointer;
            box-sizing: border-box;
          }
          li.active{
            background: #f5f5f5;
            color: $green;
            position: relative;
            &::after{
              content: '';
              position: absolute;
              top: 0;
              left: 0;
              width: 5px;
              height: 32px;
              background: linear-gradient(top,#44916c,#84c225)!important;
              background:-webkit-gradient(linear, left top, left bottom, from(#44916c), to(#84c225))!important;
            }
          }
          li:hover{
            background: #f5f5f5;
            color: $green;
            position: relative;
            &::after{
              content: '';
              position: absolute;
              top: 0;
              left: 0;
              width: 5px;
              height: 32px;
              background: linear-gradient(top,#44916c,#84c225)!important;
              background:-webkit-gradient(linear, left top, left bottom, from(#44916c), to(#84c225))!important;
            }
          }
        }
      }
      .main-right{
        width: 100%;
      }
    }
  }
</style>
